import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { ReaderMode } from '../../components/evo-reader/utils/Consts'
import EvoReader from '../../components/evo-reader';

interface ChapterProps { }

interface ChapterState {
    data: any
}

export default class Chapter extends Component<ChapterProps, ChapterState> {

    constructor(props: ChapterProps) {
        super(props)
        this.state = {
            data: {
                id: '1',
                name: '小狗凯迪爱猫咪',
                type: 2,
                pages: [
                    {
                        image: 'https://img.evomedia.cn/weapp/test/book/1080/1.jpg',
                        audio: 'https://img.evomedia.cn/weapp/test/book/audio/1.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/2.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/2.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/3.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/3.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/4.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/4.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/5.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/5.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/6.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/6.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/7.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/7.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/8.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/8.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/9.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/9.mp3'
                    },
                    {
                        image: 'https://cdn.evomedia.cn/weapp/test/book/1080/10.jpg',
                        audio: 'https://cdn.evomedia.cn/weapp/test/book/audio/10.mp3'
                    }
                ]
            }
        }
    }

    componentWillUnmount(): void {
        this.evoReader.destroy()
    }

    evoReader: EvoReader
    refReader = (node: EvoReader) => {
        this.evoReader = node
    }

    render() {
        return (
            <View>
                {this.state.data &&
                    (<EvoReader
                        ref={this.refReader}
                        useCache={false}
                        mode={ReaderMode.AUTO}
                        data={this.state.data}
                        landscape={this.state.data.type === 1} />)}
            </View>
        )
    }
}